/*
 * @Description: 
 * @Autor: 万洲
 * @Date: 2022-11-10 14:52:12
 * @LastEditors: 万洲
 * @LastEditTime: 2022-11-21 15:00:52
 */
import './public-path';
import { createApp } from 'vue'
import AppComponents from './App'
import router from './router'
import piniaPluginPersistedstate from 'pinia-plugin-persistedstate'
import { createPinia } from 'pinia';
// import { ElLoading } from "element-plus"
import El from "element-plus"
let app: any = null;
function render(props: any = {}) {
    const { container } = props;
    const pinia = createPinia()
    pinia.use(piniaPluginPersistedstate)
    app = createApp(AppComponents);
    app.use(router);
    app.use(El);
    app.use(pinia);
    app.mount(container ? container.querySelector('#app') : '#app');
}
if (!window.__POWERED_BY_QIANKUN__) {
    render();
}
/**
* bootstrap 只会在微应用初始化的时候调用一次，下次微应用重新进入时会直接调用 mount 钩子，不会再重复触发 bootstrap。
* 通常我们可以在这里做一些全局变量的初始化，比如不会在 unmount 阶段被销毁的应用级别的缓存等。
*/
export async function bootstrap() {
    console.log('%c%s', 'color: green;', '微应用初始化vue3.0 app bootstraped');
}
// function storeTest(props: any) {
//     props.onGlobalStateChange &&
//         props.onGlobalStateChange(
//             (value: any, prev: any) => console.log(`[onGlobalStateChange - ${props.name}]:`, value, prev),
//             true,
//         );
//     props.setGlobalState &&
//         props.setGlobalState({
//             ignore: props.name,
//             user: {
//                 name: props.name,
//             },
//         });
// }

export async function mount(props: any) {
    // storeTest(props);
    render(props);
    // app.config.globalProperties.$onGlobalStateChange = props.onGlobalStateChange;
    // app.config.globalProperties.$setGlobalState = props.setGlobalState;
}
export async function unmount() {
    app.unmount();
    // app._container.innerHTML = '';
    // app = null;
    // router = null;
    // history.destroy();
}
